package com.hioove.jvm;//package com.hioove;

import java.util.ArrayList;
import java.util.List;

/**
 * 堆溢出
 * -XX:+PrintGCDetails
 * -XX:+PrintCommandLineFlags
 * -XX:+PrintGCDateStamps
 * -Xms1024k
 * -Xmx1024k
 * <p>
 * java.lang.OutOfMemoryError: Java heap space
 * Dumping heap to /home/hihuzi/apps/dumpfile.hprof ...
 * Heap dump file created [2658484 bytes in 0.009 secs]
 * [Full GC (Ergonomics) [PSYoungGen: 512K->0K(1024K)] [ParOldGen: 512K->259K(512K)] 1024K->259K(1536K), [Metaspace: 2486K->2486K(1056768K)], 0.0024926 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
 * Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
 * 	at com.hioove.jvm.JavaHeapSpaceOOM.main(JavaHeapSpaceOOM.java:10)
 * Heap
 *  PSYoungGen      total 1024K, used 20K [0x00000000ffe80000, 0x0000000100000000, 0x0000000100000000)
 *   eden space 512K, 4% used [0x00000000ffe80000,0x00000000ffe85398,0x00000000fff00000)
 *   from space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)
 *   to   space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
 *  ParOldGen       total 512K, used 259K [0x00000000ffe00000, 0x00000000ffe80000, 0x00000000ffe80000)
 *   object space 512K, 50% used [0x00000000ffe00000,0x00000000ffe40ed0,0x00000000ffe80000)
 *  Metaspace       used 2518K, capacity 4486K, committed 4864K, reserved 1056768K
 *   class space    used 268K, capacity 386K, committed 512K, reserved 1048576K
 * </p>
 */
public class JavaHeapSpaceOOM {
    public static void main(String[] args) {
        List<Object> list = new ArrayList<>();
        while (true) {
            list.add(new Object());
        }
    }
}
